{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.array([1., 2., 3., 4., 5.])\n",
    "y = np.array([1., 3., 2., 3., 5.])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW0AAAD8CAYAAAC8TPVwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAANSUlEQVR4nO3cYWhd93nH8d+vkrreugl6Ua2L5QQvMBRKu1bZJaMYypZ2VUZDJ8peNNC+KAO92UrKhspUGGV7U4agNLAxEEm6hKYNxVHMKF3UQBfSwOJVitwpjaNRQiCWWqwwROJyaRXl2QsdZXYs5Z5rn6Oj5+r7AWPd47/s53KtL0f/e44cEQIA5PCupgcAAJRHtAEgEaINAIkQbQBIhGgDQCJEGwASKRVt28O2T9t+0fZ52x+rezAAwNUGS667T9ITEfHntt8t6b01zgQA2Ie73Vxj+0ZJP5V0a3AnDgA0qsyZ9q2SNiR9y/ZHJC1JujcifnX5IttTkqYk6dixY39w2223VT0rAPStpaWlVyNipNu6MmfabUnPSjoVEWdt3yfptYj4u/0+p91ux+LiYq8zA8CRZXspItrd1pV5I/KCpAsRcbZ4fFrS7dczHADg2nSNdkT8UtIrtseKQ5+Q9EKtUwEA9lT26pEvSXqkuHLkJUlfrG8kAMB+SkU7Is5J6rrXAgCoF3dEAkAiRBsAEiHaAJAI0QaARIg2ACRCtAEgEaINAIkQbQBIhGgDQCJEGwASIdoAkAjRBoBEiDYAJEK0ASARog0AiRBtAEiEaAN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291lZ5pt3Xt7tHxNOS/rfpOeoSEb+IiOeKj1+XdF47d8P2hdhxqXg4VPzqm3fhbZ+Q9GlJ9zc9C3pj+0ZJH5f0gCRFxG/2C7ZUbbT3ut29b77ojxLbJyWNSzrb7CTVKrYPzkm6KOnJiOin5/dNSV+R9GbTg9QkJP3Q9lLxIzP6ya2SNiR9q9jeut/2sf0WVxntUre743Cz/T5Jj0n6ckS81vQ8VYqI7Yj4qHbu6r3Ddl9sc9m+W9LFiFhqepYanYqI27Xz00b/stiu7BeDkm6X9C8RMS7pV5L2fU+wymhzu3tyxV7vY5IeiYj5puepS/Gt51OS7mp4lKqckvSZYt/3UUl32v52syNVKyLWi98vSnpcO9ux/eKCpAuXfed3WjsR31OV0eZ298SKN+oekHQ+Ir7R9DxVsz1ie7j4uCXpk5JebHaqakTETESciIiT2vm6+1FEfL7hsSpj+1jx5riKbYNPSeqbq7gi4peSXrG9+1P+PiFp3wsAyvyUv7L/8LXc7p6G7e9K+iNJ77d9QdLXIuKBZqeq1ClJX5C0Uuz7StJXI+IHDc5UpZskPVRc5fQuSd+LiL67NK5PfUDS4zvnFRqU9J2IeKLZkSr3JUmPFCe8L0n64n4LuY0dABLhjkgASIRoA0AiRBsAEiHaAJAI0QaARIg2ACRCtAEgkf8DZ/yhyXBKB2AAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x, y)\n",
    "plt.axis([0, 6, 0, 6])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](http://windmissing.github.io/images/2019/48.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_mean = np.mean(x)\n",
    "y_mean = np.mean(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "num = 0.0\n",
    "d = 0.0\n",
    "for x_i, y_i in zip(x, y):\n",
    "    num += (x_i - x_mean) * (y_i - y_mean)\n",
    "    d += (x_i - x_mean) ** 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = num / d\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.39999999999999947"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = y_mean - a * x_mean\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_hat = a * x + b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW0AAAD8CAYAAAC8TPVwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAYO0lEQVR4nO3deXiU1fnG8e8jRI2iptVYBUQqapBqEY1af1jcjQtVaq1L61ortWqrWKPiDrQFxH1rpYhLUVARcKugdacKmgAaREKB2rKogBoFDBjC8/vjDK2tYCYwk3fOzP25Li+T8UXvccjt63nPYu6OiIjEYaOkA4iISPpU2iIiEVFpi4hERKUtIhIRlbaISERU2iIiEUmrtM2sxMxGm9lMM3vXzPbPdjAREfmq1mledysw3t1PMLONgc2ymElERNbBmlpcY2ZbAm8BO7lW4oiIJCqdO+2dgMXAvWbWFagGLnT35V++yMx6A70BNt988707d+6c6awiInmrurp6ibu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dw/wrrvflHSeTDOzUjMrSX1dDBwGzEw2VWa4e193b+/uHQk/dy+4+6kJx8oYM9s89XCc1LDBEUDezOJy9w+AeWa2Zpe/Q4F1TgBIZ5e/dP/B67PcPRpmNhI4CNjGzOYD17r7PcmmyqjuwGlATWrcF+AKd/9LgpkyaXvg/tQsp42AR9w976bG5alvAWPDfQWtgYfcfXyykTLuV8CDqRveucBZ67pQy9hFRCKiFZEiIhFRaYuIRESlLSISEZW2iEhEVNoiIhFRaYuIRESlLSISkf8Hy6Qutfsn1VEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x, y)\n",
    "plt.plot(x, y_hat, color='r')\n",
    "plt.axis([0, 6, 0, 6])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.2"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_predict = 6\n",
    "y_predict = a * x_predict + b\n",
    "y_predict"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用我们自己的SimpleLinearRegression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "class SimpleLinearRegression1:\n",
    "    def __init__(self):\n",
    "        \"\"\"初始化Single Linear Regression模型\"\"\"\n",
    "        self.a_ = None\n",
    "        self.b_ = None\n",
    "        \n",
    "    def fit(self, x_train, y_train):\n",
    "        \"\"\"根据训练数据集X_train, y_train训练Single Linear Regression模型\"\"\"\n",
    "        assert x_train.ndim == 1, \"Simple Linear Regressor can only solve single feature training data\"\n",
    "        assert len(x_train) == len(y_train), \"the size of x_train must be equal to the size of y_train\"\n",
    "        \n",
    "        x_mean = np.mean(x_train)\n",
    "        y_mean = np.mean(y_train)\n",
    "\n",
    "        num = 0.0\n",
    "        d = 0.0\n",
    "        for x_i, y_i in zip(x_train, y_train):\n",
    "            num += (x_i - x_mean) * (y_i - y_mean)\n",
    "            d += (x_i - x_mean) ** 2\n",
    "\n",
    "        self.a_ = num / d\n",
    "        self.b_ = y_mean - self.a_ * x_mean\n",
    "        \n",
    "    def predict(self, x_predict):\n",
    "        \"\"\"给定待测数据集X_predict，返回表示x_predict的结果向量\"\"\"\n",
    "        assert x_predict.ndim == 1, \"Simple Linear Regressor can only solve single feature training data\"\n",
    "        assert self.a_ is not None and self.b_ is not None, \"must fit before predict\"\n",
    "        return [self._predict(x) for x in x_predict]\n",
    "    \n",
    "    def _predict(self, x_single):\n",
    "        \"\"\"给定单个待预测数据s_single，返回x_single的预测结果\"\"\"\n",
    "        return self.a_ * x_single + self.b_\n",
    "    \n",
    "    def __repr__(self):\n",
    "        return \"SimpleLinearRegression1()\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "reg1 = SimpleLinearRegression1()\n",
    "reg1.fit(x, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW0AAAD8CAYAAAC8TPVwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAYO0lEQVR4nO3deXiU1fnG8e8jRI2iptVYBUQqapBqEY1af1jcjQtVaq1L61ortWqrWKPiDrQFxH1rpYhLUVARcKugdacKmgAaREKB2rKogBoFDBjC8/vjDK2tYCYwk3fOzP25Li+T8UXvccjt63nPYu6OiIjEYaOkA4iISPpU2iIiEVFpi4hERKUtIhIRlbaISERU2iIiEUmrtM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p8arswXrYG9gD+4ezdgObDOZ4KZLG0td49caqz3MeBBdx+TdJ5sSf2v50vAkQlHyZTuwLGpcd9RwCFmNiLZSJnl7gtTf14EjCUMx+aL+cD8L/2f32hCia9VJktby90jlnpQdw/wrrvflHSeTDOzUjMrSX1dDBwGzEw2VWa4e193b+/uHQk/dy+4+6kJx8oYM9s89XCc1LDBEUDezOJy9w+AeWa2Zpe/Q4F1TgBIZ5e/dP/B67PcPRpmNhI4CNjGzOYD17r7PcmmyqjuwGlATWrcF+AKd/9LgpkyaXvg/tQsp42AR9w976bG5alvAWPDfQWtgYfcfXyykTLuV8CDqRveucBZ67pQy9hFRCKiFZEiIhFRaYuIRESlLSISEZW2iEhEVNoiIhFRaYuIRESlLSISkf8Hy6Qutfsn1VEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "y_hat1 = reg1.predict(x)\n",
    "\n",
    "plt.scatter(x, y)\n",
    "plt.plot(x, y_hat1, color='r')\n",
    "plt.axis([0, 6, 0, 6])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
